package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.HistoryService;
import com.sky.service.OrdermmService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/order")
@Slf4j
@Api(tags = "订单查询")
public class HistorderController {
    @Autowired
    private OrdermmService ordermmService;
    @Autowired
    private  HistoryService historyService;

    @GetMapping("/conditionSearch")
    @ApiOperation("订单查询")
    public Result<PageResult> orderlist(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = ordermmService.apihistorylist(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/statistics")
    @ApiOperation("根据状态查询")
    public Result<OrderStatisticsVO> orderlisttrpe() {
        OrderStatisticsVO orderStatisticsVO = ordermmService.listcount();
        return Result.success(orderStatisticsVO);
    }

    /*
     * 接单
     * */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result jiedan(@RequestBody OrdersConfirmDTO confirmDTO) {
        ordermmService.updateBid(confirmDTO);
        return Result.success();
    }
    /*
    * 拒单
    * */
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result judan(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        ordermmService.jection(ordersRejectionDTO);
        return Result.success();
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        ordermmService.cancel(ordersCancelDTO);
        return Result.success();
    }
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result Delivery(@PathVariable long id){
        ordermmService.delivery(id);
        return Result.success();
    }

    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result finish(@PathVariable long id){
        ordermmService.finish(id);
        return Result.success();
    }

    //订单详情
    @GetMapping("details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO>xiangqin(@PathVariable long id){
           OrderVO orderVO = historyService.list(id);
           return Result.success(orderVO);

    }
}
